package com.study.zk.lock.zookeeper;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @author: chenhs
 * @date: Created in 10:16 2020/2/5
 **/
public class DemoThread {

    static CyclicBarrier cyclicBarrier = new CyclicBarrier(10);

    static class DemoRun implements Runnable {

        private int i;

        public DemoRun(int i) {
            this.i = i;
        }

        @Override
        public void run() {
            try {
                DemoService demoService = new DemoService();
                cyclicBarrier.await();
                demoService.sayHello("name_" + i);
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (BrokenBarrierException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(new DemoRun(i)).start();
        }
    }
}